﻿using System.Collections;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Trippy.CollidableGameComponents;
using Trippy.Levels;

namespace Trippy.Effects
{
    // Effects are transformations or changes applied to CollidableGameComponent(s). Intended to be used for effects that span multiple objects that need to be centrally managed or coordinated.
    public class Effect : GameComponent
    {
        protected List<CollidableGameComponent> components = new List<CollidableGameComponent>();
        public List<CollidableGameComponent> Components { get { return components; } }
        protected List<Vector2> initialPositions = new List<Vector2>();

        public Effect(Level level)
            : base(level.Game)
        {
        }

        public Effect(Level level, IEnumerable<CollidableGameComponent> components)
            : base(level.Game)
        {
            foreach (CollidableGameComponent c in components)
            {
                Components.Add(c);
                initialPositions.Add(c.Position);
            }
        }

        public void Add(CollidableGameComponent component)
        {
            Components.Add(component);
            initialPositions.Add(component.Position);
        }

        /// <summary>
        /// Resets the position of all components to what they were when they were added to the effect.
        /// </summary>
        public void Reset()
        {
            for (int i = 0; i < Components.Count; i++)
            {
                Components[i].Position = initialPositions[i];
            }
        }

        public IEnumerator GetEnumerator()
        {
            return Components.GetEnumerator();
        }

    }
}
